//
// Created by thomas on 2020/5/21.
//
#ifndef __ZM32_MESSAGE_H__
#define __ZM32_MESSAGE_H__

#define PRIVATE_PROFILE         0xC105
#define PRIVATE_CLUSTER         0x0011
#define PRIVATE_SRCENDPOINT     0xE8
#define PRIVATE_DSTENDPOINT     0xE8

#define MAX_GROUP_NUM           5

#define ZM32_CONF_TMP_ID    0xDEDFEF
#define ZM32_CONF_PST_ID    0xABBCCD
#define ZM32_SPC_FRAME_ID   0xADDBBE

#define ZM32_FRAME_TAIL     0xAA

#define ZM32_PROTO_TYPE     0x0004

#define MAKE_HEADER( PROTOCOLID, CMDID )  ( (PROTOCOLID << 8) | (CMDID & 0xFF) )
#define EXTRACT_PROTO( TYPE )  ( (TYPE >> 8) & 0x00FFFFFF )


/* 串口命令标识 */
typedef enum
{
/* 临时生效命令，本地参数设置 */
    E_SL_TMP_LOC_CONF_SET = MAKE_HEADER(ZM32_CONF_TMP_ID, 0x22),         /*配置发送选项*/
    E_SL_TMP_LOC_CONF_GROUP_ID = MAKE_HEADER(ZM32_CONF_TMP_ID, 0x23),         /*配置目标组号*/
    E_SL_TMP_LOC_FACTORY_MODE = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xD0),         /*进入测试模式*/
    E_SL_TMP_LOC_SET_NWK_ADDR = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xD2),         /*修改目标网络地址*/
    E_SL_TMP_LOC_SLEEP = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xD8),         /*进入休眠*/
    E_SL_TMP_LOC_TX_MODE = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xD9),         /*设置发送模式*/
    E_SL_TMP_LOC_BC_ACK_DELAY = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xF7),         /*设置广播命令应答延时*/

/* 临时生效命令，基于mac地址通讯 */
    E_SL_TMP_MAC_IO_DIRECTION = MAKE_HEADER(ZM32_CONF_TMP_ID, 0x54),         /*设置IO方向*/
    E_SL_TMP_MAC_IO_READ = MAKE_HEADER(ZM32_CONF_TMP_ID, 0x55),         /*读取IO状态*/
    E_SL_TMP_MAC_IO_WRITE = MAKE_HEADER(ZM32_CONF_TMP_ID, 0x56),         /*设置IO状态*/
    E_SL_TMP_MAC_AD_READ = MAKE_HEADER(ZM32_CONF_TMP_ID, 0x57),         /*读取AD*/
    E_SL_TMP_MAC_QUERY_ROUTE_TABLE = MAKE_HEADER(ZM32_CONF_TMP_ID, 0x5C),         /*查询路由表(只有路由及协调器有效)*/
    E_SL_TMP_MAC_NETWORK_SEARCH = MAKE_HEADER(ZM32_CONF_TMP_ID, 0x5D),         /*搜索存在的网络*/
    E_SL_TMP_MAC_RSSI = MAKE_HEADER(ZM32_CONF_TMP_ID, 0x5E),         /*查询节点的接收信号强度*/
    E_SL_TMP_MAC_RX_MODE = MAKE_HEADER(ZM32_CONF_TMP_ID, 0x73),         /*设置接收模式*/
    E_SL_TMP_MAC_SET_DST_MAC = MAKE_HEADER(ZM32_CONF_TMP_ID, 0x74),         /*设置目标MAC地址*/
    E_SL_TMP_MAC_SET_ACK_DELAY = MAKE_HEADER(ZM32_CONF_TMP_ID, 0x76),         /*命令的应答时间*/
    E_SL_TMP_MAC_GET_NWK_ADDR = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xFE),         /*获取网络地址*/

/* 临时生效命令，基于nwk地址通讯 */
    E_SL_TMP_NWK_IO_DIRECTION = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xD4),         /*设置IO方向*/
    E_SL_TMP_NWK_IO_READ = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xD5),         /*读取IO状态*/
    E_SL_TMP_NWK_IO_WRITE = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xD6),         /*设置IO状态*/
    E_SL_TMP_NWK_AD_READ = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xD7),         /*读取AD*/
    E_SL_TMP_NWK_QUERY_ROUTE_TABLE = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xDC),         /*查询路由表(只有路由及协调器有效)*/
    E_SL_TMP_NWK_NETWORK_SEARCH = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xDD),         /*搜索存在的网络*/
    E_SL_TMP_NWK_RSSI = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xDE),         /*查询节点的接收信号强度*/
    E_SL_TMP_NWK_RX_MODE = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xF3),         /*设置接收模式*/
    E_SL_TMP_NWK_SET_MAC_ADDR = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xF4),         /*设置目标MAC地址*/
    E_SL_TMP_NWK_GET_GPLOT = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xF5),         /*获取网络拓扑*/
    E_SL_TMP_NWK_SET_ACK_DELAY = MAKE_HEADER(ZM32_CONF_TMP_ID, 0xF6),         /*命令的应答时间*/

/* 永久生效命令，本地参数设置 */
    E_SL_PST_LOC_CONF_READ = MAKE_HEADER(ZM32_CONF_PST_ID, 0xD1),         /*读取本地配置*/
    E_SL_PST_LOC_ENABLE_WHITELIST = MAKE_HEADER(ZM32_CONF_PST_ID, 0x20),         /*启用白名单*/
    E_SL_PST_LOC_CONF_WHITELIST = MAKE_HEADER(ZM32_CONF_PST_ID, 0x21),         /*配置白名单*/
    E_SL_PST_LOC_CONF_TX_OPTION = MAKE_HEADER(ZM32_CONF_PST_ID, 0x22),         /*配置发送选项*/
    E_SL_PST_LOC_CONF_WHITELIST_NEW = MAKE_HEADER(ZM32_CONF_PST_ID, 0x23),         /*配置白名单(新接口)*/
    E_SL_PST_LOC_REFRESH_ROUTE_TABLE = MAKE_HEADER(ZM32_CONF_PST_ID, 0x26),         /*请求更新远程路由到本地路由的路径*/
    E_SL_PST_LOC_AD_HOC = MAKE_HEADER(ZM32_CONF_PST_ID, 0x27),         /*配置自组网*/
    //E_SL_PST_LOC_START_NETWORK = MAKE_HEADER(ZM32_CONF_PST_ID, 0xE5),         /*配置自组网*/
    E_SL_PST_LOC_PERMIT_JOIN = MAKE_HEADER(ZM32_CONF_PST_ID, 0xE6),         /*开启入网许可*/
    E_SL_PST_LOC_COOR_STATE = MAKE_HEADER(ZM32_CONF_PST_ID, 0xE8),         /*查询协调器状态*/
    E_SL_PST_LOC_BACKUP = MAKE_HEADER(ZM32_CONF_PST_ID, 0xFA),         /*备份*/
    E_SL_PST_LOC_RESTORE = MAKE_HEADER(ZM32_CONF_PST_ID, 0xFB),         /*恢复*/

/* 永久生效命令，基于mac地址通讯 */
    E_SL_PST_MAC_SET_CHANNEL = MAKE_HEADER(ZM32_CONF_PST_ID, 0x40),         /*设置信道*/
    E_SL_PST_MAC_SET_PANID = MAKE_HEADER(ZM32_CONF_PST_ID, 0x41),         /*设置PAN ID*/
    E_SL_PST_MAC_CTEATE_GROUP = MAKE_HEADER(ZM32_CONF_PST_ID, 0x42),         /*创建分组*/
    E_SL_PST_MAC_SET_GROUP_ID = MAKE_HEADER(ZM32_CONF_PST_ID, 0x43),         /*设置目标组ID*/
    E_SL_PST_MAC_SEARCH_NODE = MAKE_HEADER(ZM32_CONF_PST_ID, 0x54),         /*搜索网络内的设备*/
    E_SL_PST_MAC_GET_REMOTE_CONF = MAKE_HEADER(ZM32_CONF_PST_ID, 0x55),         /*获取远端节点配置信息*/
    E_SL_PST_MAC_SET_REMOTE_CONF = MAKE_HEADER(ZM32_CONF_PST_ID, 0x56),         /*设置远端节点配置信息*/
    E_SL_PST_MAC_RST_REMOTE = MAKE_HEADER(ZM32_CONF_PST_ID, 0x59),         /*复位远端节点*/
    E_SL_PST_MAC_RESTORE_REMOTE = MAKE_HEADER(ZM32_CONF_PST_ID, 0x5A),         /*恢复出厂远端节点*/
    E_SL_PST_MAC_ENABLE_PASSWD = MAKE_HEADER(ZM32_CONF_PST_ID, 0x5E),         /*远端节点密码使能*/
    E_SL_PST_MAC_LOGIN = MAKE_HEADER(ZM32_CONF_PST_ID, 0x5F),         /*远端节点登陆*/
    E_SL_PST_MAC_IO_DIRECTION = MAKE_HEADER(ZM32_CONF_PST_ID, 0x61),         /*设置IO方向*/
    E_SL_PST_MAC_AD_CONF = MAKE_HEADER(ZM32_CONF_PST_ID, 0x62),         /*IO/AD 采集设置*/
    E_SL_PST_MAC_IO_WRITE = MAKE_HEADER(ZM32_CONF_PST_ID, 0x63),         /*I/O 控制输出*/
    E_SL_PST_MAC_PWM_CONF = MAKE_HEADER(ZM32_CONF_PST_ID, 0x64),         /*PWM 控制输出*/
    E_SL_PST_MAC_SET_NWK_ADDR = MAKE_HEADER(ZM32_CONF_PST_ID, 0x69),         /*设置目标网络地址*/
    E_SL_PST_MAC_GET_NODE_TYPE = MAKE_HEADER(ZM32_CONF_PST_ID, 0x6A),         /*读取节点设备类型*/
    E_SL_PST_MAC_GET_MAC_ADDR = MAKE_HEADER(ZM32_CONF_PST_ID, 0x6B),         /*查询子终端节点的 MAC 地址(只有路由及协调器有效)*/
    E_SL_PST_MAC_GET_PARENT_MAC_ADDR = MAKE_HEADER(ZM32_CONF_PST_ID, 0x6C),         /*查询父节点的MAC地址*/
    E_SL_PST_MAC_GET_MWK_ADDR = MAKE_HEADER(ZM32_CONF_PST_ID, 0x6D),         /*查询网络地址*/
    E_SL_PST_MAC_SET_KEY = MAKE_HEADER(ZM32_CONF_PST_ID, 0x6E),         /*设置模块秘钥*/
    E_SL_PST_MAC_GET_KEY = MAKE_HEADER(ZM32_CONF_PST_ID, 0x6F),         /*读取模块秘钥*/
    E_SL_PST_MAC_ENTER_OTA_MODE = MAKE_HEADER(ZM32_CONF_PST_ID, 0x71),         /*进入升级模式*/
    E_SL_PST_MAC_OTA = MAKE_HEADER(ZM32_CONF_PST_ID, 0x72),         /*固件升级*/
    E_SL_PST_MAC_SET_RX_MODE = MAKE_HEADER(ZM32_CONF_PST_ID, 0x73),         /*设置接收模式*/
    E_SL_PST_MAC_SET_MAC_ADDR = MAKE_HEADER(ZM32_CONF_PST_ID, 0x74),         /*设置目标MAC地址*/
    E_SL_PST_MAC_SET_TX_MODE = MAKE_HEADER(ZM32_CONF_PST_ID, 0x75),         /*设置发送模式*/
    E_SL_PST_MAC_ENABLE_BLACK_LIST = MAKE_HEADER(ZM32_CONF_PST_ID, 0x76),         /*启用黑名单*/
    E_SL_PST_MAC_CONF_BLACK_LIST = MAKE_HEADER(ZM32_CONF_PST_ID, 0x77),         /*设置黑名单*/

/* 永久生效命令，基于nwk地址通讯 */
    E_SL_PST_NWK_SET_CHANNEL = MAKE_HEADER(ZM32_CONF_PST_ID, 0xC0),         /*设置信道*/
    E_SL_PST_NWK_SET_PANID = MAKE_HEADER(ZM32_CONF_PST_ID, 0xC1),         /*设置PAN ID*/
    E_SL_PST_NWK_CTEATE_GROUP = MAKE_HEADER(ZM32_CONF_PST_ID, 0xC2),         /*创建分组*/
    E_SL_PST_NWK_SET_GROUP_ID = MAKE_HEADER(ZM32_CONF_PST_ID, 0xC3),         /*设置目标组ID*/
    E_SL_PST_NWK_SEARCH_NODE = MAKE_HEADER(ZM32_CONF_PST_ID, 0xD4),         /*搜索网络内的设备*/
    E_SL_PST_NWK_GET_REMOTE_CONF = MAKE_HEADER(ZM32_CONF_PST_ID, 0xD5),         /*获取远端节点配置信息*/
    E_SL_PST_NWK_SET_REMOTE_CONF = MAKE_HEADER(ZM32_CONF_PST_ID, 0xD6),         /*设置远端节点配置信息*/
    E_SL_PST_NWK_RST_REMOTE = MAKE_HEADER(ZM32_CONF_PST_ID, 0xD9),         /*复位远端节点*/
    E_SL_PST_NWK_RESTORE_REMOTE = MAKE_HEADER(ZM32_CONF_PST_ID, 0xDA),         /*恢复出厂远端节点*/
    E_SL_PST_NWK_ENABLE_PASSWD = MAKE_HEADER(ZM32_CONF_PST_ID, 0xDE),         /*远端节点密码使能*/
    E_SL_PST_NWK_LOGIN = MAKE_HEADER(ZM32_CONF_PST_ID, 0xDF),         /*远端节点登陆*/
    E_SL_PST_NWK_IO_DIRECTION = MAKE_HEADER(ZM32_CONF_PST_ID, 0xE1),         /*设置IO方向*/
    E_SL_PST_NWK_AD_CONF = MAKE_HEADER(ZM32_CONF_PST_ID, 0xE2),         /*IO/AD 采集设置*/
    E_SL_PST_NWK_IO_WRITE = MAKE_HEADER(ZM32_CONF_PST_ID, 0xE3),         /*I/O 控制输出*/
    E_SL_PST_NWK_PWM_CONF = MAKE_HEADER(ZM32_CONF_PST_ID, 0xE4),         /*PWM 控制输出*/
    E_SL_PST_NWK_SET_NWK_ADDR = MAKE_HEADER(ZM32_CONF_PST_ID, 0xE9),         /*设置目标网络地址*/
    E_SL_PST_NWK_GET_NODE_TYPE = MAKE_HEADER(ZM32_CONF_PST_ID, 0xEA),         /*读取节点设备类型*/
    E_SL_PST_NWK_GET_NWK_ADDR = MAKE_HEADER(ZM32_CONF_PST_ID, 0xEB),         /*查询子终端节点的网络地址(只有路由及协调器有效)*/
    E_SL_PST_NWK_GET_PARENT_NWK_ADDR = MAKE_HEADER(ZM32_CONF_PST_ID, 0xEC),         /*查询父节点的网络地址*/
    E_SL_PST_NWK_GET_MAC_ADDR = MAKE_HEADER(ZM32_CONF_PST_ID, 0xED),         /*查询MAC地址*/
    E_SL_PST_NWK_SET_KEY = MAKE_HEADER(ZM32_CONF_PST_ID, 0xEE),         /*设置模块秘钥*/
    E_SL_PST_NWK_GET_KEY = MAKE_HEADER(ZM32_CONF_PST_ID, 0xEF),         /*读取模块秘钥*/
    E_SL_PST_NWK_ENTER_OTA_MODE = MAKE_HEADER(ZM32_CONF_PST_ID, 0xF1),         /*进入升级模式*/
    E_SL_PST_NWK_OTA = MAKE_HEADER(ZM32_CONF_PST_ID, 0xF2),         /*固件升级*/
    E_SL_PST_NWK_SET_RX_MODE = MAKE_HEADER(ZM32_CONF_PST_ID, 0xF3),         /*设置接收模式*/
    E_SL_PST_NWK_SET_MAC_ADDR = MAKE_HEADER(ZM32_CONF_PST_ID, 0xF4),         /*设置目标MAC地址*/
    E_SL_PST_NWK_SET_TX_MODE = MAKE_HEADER(ZM32_CONF_PST_ID, 0xF5),         /*设置发送模式*/
    E_SL_PST_NWK_BC_ACK_DELAY = MAKE_HEADER(ZM32_CONF_PST_ID, 0xF6),         /*设置广播应答延时*/
    E_SL_PST_NWK_ENABLE_BLACK_LIST = MAKE_HEADER(ZM32_CONF_PST_ID, 0xF7),         /*启用黑名单*/
    E_SL_PST_NWK_CONF_BLACK_LIST = MAKE_HEADER(ZM32_CONF_PST_ID, 0xF8),         /*设置黑名单*/


/* 特殊帧 */
    E_SL_SPC_TX_FRAME = MAKE_HEADER(ZM32_SPC_FRAME_ID, 0x10),         /*发送特殊帧*/
    E_SL_SPC_GROUP_TX_FRAME = MAKE_HEADER(ZM32_SPC_FRAME_ID, 0x11),         /*以组播方式发送特殊帧*/
    E_SL_SPC_RX_FRAME = MAKE_HEADER(ZM32_SPC_FRAME_ID, 0x90),         /*接收特殊帧*/
    E_SL_SPC_GROUP_RX_FRAME = MAKE_HEADER(ZM32_SPC_FRAME_ID, 0x91),         /*以组播方式接收特殊帧*/
} teSL_MsgType;

/**
 * @brief 配置发送选项请求
 */
typedef struct tmploc_conf_tx_opt_req
{
    /*rw字节为 0，表示该命令为读参数命令，为 1 表示写参数命令，当为读参数命令时，该命令其他字段忽略。*/
    unsigned char rw;
    unsigned short profileid;
    unsigned short clusterid;
    unsigned char srcendpoint;
    unsigned char dstendpoint;
    /*保留字段*/
    unsigned char reserve[6];
}__attribute__((__packed__)) tmploc_conf_tx_opt_req_ts;

/**
 * @brief 配置发送选项回复
 */
typedef struct tmploc_conf_tx_opt_resp
{
    unsigned short profileid;
    unsigned short clusterid;
    unsigned char srcendpoint;
    unsigned char dstendpoint;
    unsigned char reserve[6];
}__attribute__((__packed__)) tmploc_conf_tx_opt_resp_ts;

/**
 * @brief 配置目标组号请求
 */
typedef struct tmploc_conf_groupid_req
{
    /*目标组号 0x0000~0xFFFF*/
    unsigned short groupid;
}__attribute__((__packed__)) tmploc_conf_groupid_req_ts;

/**
 * @brief 配置目标组号回复
 */
typedef struct tmploc_conf_groupid_resp
{
    /*操作结果 0x00：设置成功， 其他：失败*/
    unsigned short result;
}__attribute__((__packed__)) tmploc_conf_groupid_resp_ts;

/**
 * @brief 修改目标网络地址请求
 */
typedef struct tmploc_set_nwkaddr_req
{
    /**
     * 目标网络地址：0x0000~0xFFFF
     *   0xFFFF 代表广播给所有设备；
     *   0xFFFD 代表广播给所有非睡眠设备；
     *   0xFFFC 代表广播给协调器和路由设备；
     *   0xFFFB 代表组播，使用目标组号。
     */
    unsigned short nwkaddr;
}__attribute__((__packed__)) tmploc_set_nwkaddr_req_ts;

/**
 * @brief 修改目标网络地址回复
 */
typedef struct tmploc_set_nwkaddr_resp
{
    /*操作结果 0x00：设置成功， 其他：失败*/
    unsigned char result;
}__attribute__((__packed__)) tmploc_set_nwkaddr_resp_ts;

/**
 * @brief 进入休眠请求
 *              休眠命令无返回，可通过拉低唤醒管脚（WAKE）进行唤醒，也可通过设置定时唤醒或者 IO 唤醒
 */
typedef struct tmploc_enter_sleep_req
{
    /*0x01：进入休眠 其他:无效*/
    unsigned char sleep;
}__attribute__((__packed__)) tmploc_enter_sleep_req_ts;

/**
 * @brief 设置发送模式请求
 */
typedef struct tmploc_set_tx_mode_req
{
    /**
     * txmode:数据传输方式
     *  0：单播模式
     *  1：广播给所有设备
     *  2：广播给所有非睡眠设备
     *  3：广播给协调器和所有路由器
     *  4：组播模式
     */
    unsigned char txmode: 3;

    /**
     * needmac: 是否需要添加源MAC 地址
     *  0: 否
     *  1: 是
     */
    unsigned char needmac: 1;

    /**
     * addressmode: 寻址方式
     *  0: 网络地址
     *  1: MAC地址
     */
    unsigned char addressmode: 1;

    /**
     * format: 数据包格式
     *  0：数据（根据数据的目标地址进行发送）
     *  1：指定网络地址+数据
     *  2：指定 MAC 地址+数据
     *  3：发送帧格式
     */
    unsigned char format: 2;
    unsigned char reserve: 1;
}__attribute__((__packed__)) tmploc_set_tx_mode_req_ts;

/**
 * @brief 设置发送模式回复
 */
typedef struct tmploc_set_tx_mode_resp
{
    /**
     * state: 状态
     *   0x00：设置成功
     *   其它：设置失败
     */
    unsigned char state;
}__attribute__((__packed__)) tmploc_set_tx_mode_resp_ts;

/**
 * @brief 设置广播命令应答延时请求，无回复。
 */
typedef struct tmploc_set_bc_ack_delay_req
{
    /*移动位数*/
    unsigned char shiftbit: 3;
    unsigned char reserve: 4;

    /*移动方向， 0:右移 1:左移*/
    unsigned char shiftdir: 1;
}__attribute__((__packed__)) tmploc_set_bc_ack_delay_req_ts;

//===============================================================================================
//========================================基于 AMC 地址==========================================
//===============================================================================================

/**
 * @brief 设置 I/O 输入输出请求
 */
typedef struct tmpmac_set_io_dir_req
{
    unsigned long long macaddr;
    unsigned char io0: 1;
    unsigned char io1: 1;
    unsigned char io2: 1;
    unsigned char io3: 1;
}__attribute__((__packed__)) tmpmac_set_io_dir_req_ts;

/**
 * @brief 设置 I/O 输入输出回复
 */
typedef struct tmpmac_set_io_dir_resp
{
    unsigned long long macaddr;
    unsigned char state;
}__attribute__((__packed__)) tmpmac_set_io_dir_resp_ts;

/**
 * @brief 读取 I/O 状态请求
 */
typedef struct tmpmac_io_read_req
{
    unsigned long long macaddr;
}__attribute__((__packed__)) tmpmac_io_read_req_ts;

/**
 * @brief 读取 I/O 状态回复
 */
typedef struct tmpmac_io_read_resp
{
    unsigned long long macaddr;
    unsigned char io0: 1;
    unsigned char io1: 1;
    unsigned char io2: 1;
    unsigned char io3: 1;
}__attribute__((__packed__)) tmpmac_io_read_resp_ts;

/**
 * @brief 设置I/O 状态请求
 */
typedef struct tmpmac_io_write_req
{
    unsigned long long macaddr;
    unsigned char io0: 1;
    unsigned char io1: 1;
    unsigned char io2: 1;
    unsigned char io3: 1;
}__attribute__((__packed__)) tmpmac_io_write_req_ts;

/**
 * @brief 设置I/O 状态回复
 */
typedef struct tmpmac_io_write_resp
{
    unsigned long long macaddr;
    unsigned char state;
}__attribute__((__packed__)) tmpmac_io_write_resp_ts;

/**
 * @brief 读取AD请求
 */
typedef struct tmpmac_adc_read_req
{
    unsigned long long macaddr;
    unsigned char no;           /*AD通道号（1~4）*/
}__attribute__((__packed__)) tmpmac_adc_read_req_ts;

/**
 * @brief 读取AD回复
 */
typedef struct tmpmac_adc_read_resp
{
    unsigned long long macaddr;
    unsigned short value;       /*AD值*/
}__attribute__((__packed__)) tmpmac_adc_read_resp_ts;

/**
 * @brief 查询路由表(只有路由及协调器有效)请求
 */
typedef struct tmpmac_route_request_req
{
    unsigned long long macaddr;
    unsigned char block;            /*分块号*/
}__attribute__((__packed__)) tmpmac_route_request_req_ts;

struct route_table
{
    unsigned short targetaddr;      /*目标网络地址*/
    unsigned short nexthopaddr;     /*下一跳网络地址*/
}__attribute__((__packed__));

/**
 * @brief 查询路由表(只有路由及协调器有效)回复
 */
typedef struct tmpmac_route_request_resp
{
    unsigned long long macaddr;
    unsigned char block;    /*分块号*/
    unsigned char num;      /*条目数，即struct route_table* prtable 个数*/
    struct route_table *proute_table;
}__attribute__((__packed__)) tmpmac_route_request_resp_ts;

/**
 * @brief 搜索存在的网络请求
 */
typedef struct tmpmac_nwk_search_req
{
    unsigned long long macaddr;
    unsigned short channelmask; /*信道掩码*/
    unsigned short timeout;     /*每个信道的扫描时间，单位ms*/
}__attribute__((__packed__)) tmpmac_nwk_search_req_ts;

struct paninfo
{
    unsigned short panid;
    unsigned short nwkaddr;
    unsigned char channel;      /*信道 11~26*/
    char rssi;                  /*信号强度，单位dBm*/
    unsigned char joinable;     /*是否开放了入网许可*/
}__attribute__((__packed__));

/**
 * @brief 搜索存在的网络回复
 */
typedef struct tmpmac_nwk_search_resp
{
    unsigned long long macaddr;
    unsigned char num;
    struct paninfo *ppaninfo;
}__attribute__((__packed__)) tmpmac_nwk_search_resp_ts;

/**
 * @brief 获取目标信号强度请求
 */
typedef struct tmpmac_rssi_req
{
    unsigned long long macaddr;
}__attribute__((__packed__)) tmpmac_rssi_req_ts;

/**
 * @brief 获取目标信号强度回复
 */
typedef struct tmpmac_rssi_resp
{
    unsigned long long macaddr;
    char localrssi;         /*本地信号接收强度，单位dBm*/
    char remoterssi;        /*远端信号接收强度，单位dBm*/
}__attribute__((__packed__)) tmpmac_rssi_resp_ts;

/**
 * @brief 设置发送模式请求
 */
typedef struct tmpmac_set_rx_mode_req
{
    unsigned long long macaddr;
    /*
     *  0：数据
     *  1：源网络地址+数据
     *  2：源 MAC 地址+数据
     *  3：源网络地址+源 MAC 地址+数据
     *  4：接收帧格式 
     */
    unsigned char mode: 3;
    unsigned char reserve: 5;
}__attribute__((__packed__)) tmpmac_set_rx_mode_req_ts;

/**
 * @brief 设置发送模式回复
 */
typedef struct tmpmac_set_rx_mode_resp
{
    unsigned long long macaddr;
    unsigned char state;
}__attribute__((__packed__)) tmpmac_set_rx_mode_resp_ts;

/**
 * @brief 设置目标mac地址请求
 */
typedef struct tmpmac_set_dstmac_req
{
    unsigned long long macaddr;
    unsigned long long dst_macaddr;
}__attribute__((__packed__)) tmpmac_set_dstmac_req_ts;

/**
 * @brief 设置目标mac地址回复
 */
typedef struct tmpmac_set_dstmac_resp
{
    unsigned long long macaddr;
    unsigned char state;
}__attribute__((__packed__)) tmpmac_set_dstmac_resp_ts;

/**
 * @brief 测量通讯延迟请求
 */
typedef struct tmpmac_latency_req
{
    unsigned long long macaddr;
}__attribute__((__packed__)) tmpmac_ping_req_ts;

/**
 * @brief 测量通讯延迟回复
 */
typedef struct tmpmac_latency_resp
{
    unsigned long long macaddr;
    unsigned short latency;     /*延迟，单位ms*/
}__attribute__((__packed__)) tmpmac_ping_resp_ts;

/**
 * @brief 获取网络地址请求
 */
typedef struct tmpmac_get_nwk_addr_req
{
    unsigned long long macaddr;
}__attribute__((__packed__)) tmpmac_get_nwk_addr_req_ts;

/**
 * @brief 获取网络地址回复
 */
typedef struct tmpmac_get_nwk_addr_resp
{
    unsigned long long macaddr;
    unsigned short nwkaddr;
}__attribute__((__packed__)) tmpmac_get_nwk_addr_resp_ts;

//===============================================================================================
//========================================基于网络地址===========================================
//===============================================================================================

/**
 * @brief 设置 I/O 输入输出请求
 */
typedef struct tmpnwk_set_io_dir_req
{
    unsigned short nwkaddr;
    unsigned char io0: 1;
    unsigned char io1: 1;
    unsigned char io2: 1;
    unsigned char io3: 1;
}__attribute__((__packed__)) tmpnwk_set_io_dir_req_ts;

/**
 * @brief 设置 I/O 输入输出回复
 */
typedef struct tmpnwk_set_io_dir_resp
{
    unsigned short nwkaddr;
    unsigned char state;
}__attribute__((__packed__)) tmpnwk_set_io_dir_resp_ts;

/**
 * @brief 读取 I/O 状态请求
 */
typedef struct tmpnwk_io_read_req
{
    unsigned short nwkaddr;
}__attribute__((__packed__)) tmpnwk_io_read_req_ts;

/**
 * @brief 读取 I/O 状态回复
 */
typedef struct tmpnwk_io_read_resp
{
    unsigned short nwkaddr;
    unsigned char io0: 1;
    unsigned char io1: 1;
    unsigned char io2: 1;
    unsigned char io3: 1;
}__attribute__((__packed__)) tmpnwk_io_read_resp_ts;

/**
 * @brief 设置I/O 状态请求
 */
typedef struct tmpnwk_io_write_req
{
    unsigned short nwkaddr;
    unsigned char io0: 1;
    unsigned char io1: 1;
    unsigned char io2: 1;
    unsigned char io3: 1;
}__attribute__((__packed__)) tmpnwk_io_write_req_ts;

/**
 * @brief 设置I/O 状态回复
 */
typedef struct tmpnwk_io_write_resp
{
    unsigned short nwkaddr;
    unsigned char state;
}__attribute__((__packed__)) tmpnwk_io_write_resp_ts;

/**
 * @brief 读取AD请求
 */
typedef struct tmpnwk_adc_read_req
{
    unsigned short nwkaddr;
    unsigned char no;           /*AD通道号（1~4）*/
}__attribute__((__packed__)) tmpnwk_adc_read_req_ts;

/**
 * @brief 读取AD回复
 */
typedef struct tmpnwk_adc_read_resp
{
    unsigned short nwkaddr;
    unsigned short value;       /*AD值*/
}__attribute__((__packed__)) tmpnwk_adc_read_resp_ts;

/**
 * @brief 查询路由表(只有路由及协调器有效)请求
 */
typedef struct tmpnwk_route_request_req
{
    unsigned short nwkaddr;
    unsigned char block;            /*分块号*/
}__attribute__((__packed__)) tmpnwk_route_request_req_ts;

/**
 * @brief 查询路由表(只有路由及协调器有效)回复
 */
typedef struct tmpnwk_route_request_resp
{
    unsigned short nwkaddr;
    unsigned char block;    /*分块号*/
    unsigned char num;      /*条目数，即struct route_table* prtable 个数*/
    struct route_table *proute_table;
}__attribute__((__packed__)) tmpnwk_route_request_resp_ts;

/**
 * @brief 搜索存在的网络请求
 */
typedef struct tmpnwk_nwk_search_req
{
    unsigned short nwkaddr;
    unsigned short channelmask; /*信道掩码*/
    unsigned short timeout;     /*每个信道的扫描时间，单位ms*/
}__attribute__((__packed__)) tmpnwk_nwk_search_req_ts;

/**
 * @brief 搜索存在的网络回复
 */
typedef struct tmpnwk_nwk_search_resp
{
    unsigned short nwkaddr;
    unsigned char num;
    struct paninfo *ppaninfo;
}__attribute__((__packed__)) tmpnwk_nwk_search_resp_ts;

/**
 * @brief 获取目标信号强度请求
 */
typedef struct tmpnwk_rssi_req
{
    unsigned short nwkaddr;
}__attribute__((__packed__)) tmpnwk_rssi_req_ts;

/**
 * @brief 获取目标信号强度回复
 */
typedef struct tmpnwk_rssi_resp
{
    unsigned short nwkaddr;
    char localrssi;         /*本地信号接收强度，单位dBm*/
    char remoterssi;        /*远端信号接收强度，单位dBm*/
}__attribute__((__packed__)) tmpnwk_rssi_resp_ts;

/**
 * @brief 设置发送模式请求
 */
typedef struct tmpnwk_set_rx_mode_req
{
    unsigned short nwkaddr;
    /*
     *  0：数据
     *  1：源网络地址+数据
     *  2：源 MAC 地址+数据
     *  3：源网络地址+源 MAC 地址+数据
     *  4：接收帧格式 
     */
    unsigned char mode: 3;
    unsigned char reserve: 5;
}__attribute__((__packed__)) tmpnwk_set_rx_mode_req_ts;

/**
 * @brief 设置发送模式回复
 */
typedef struct tmpnwk_set_rx_mode_resp
{
    unsigned short nwkaddr;
    unsigned char state;
}__attribute__((__packed__)) tmpnwk_set_rx_mode_resp_ts;

/**
 * @brief 设置目标mac地址请求
 */
typedef struct tmpnwk_set_dstmac_req
{
    unsigned short nwkaddr;
    unsigned long long dst_macaddr;
}__attribute__((__packed__)) tmpnwk_set_dstmac_req_ts;

/**
 * @brief 设置目标mac地址回复
 */
typedef struct tmpnwk_set_dstmac_resp
{
    unsigned short nwkaddr;
    unsigned char state;
}__attribute__((__packed__)) tmpnwk_set_dstmac_resp_ts;

/**
 * @brief 测量通讯延迟请求
 */
typedef struct tmpnwk_latency_req
{
    unsigned short nwkaddr;
}__attribute__((__packed__)) tmpnwk_ping_req_ts;

/**
 * @brief 测量通讯延迟回复
 */
typedef struct tmpnwk_latency_resp
{
    unsigned short nwkaddr;
    unsigned short latency;     /*延迟，单位ms*/
}__attribute__((__packed__)) tmpnwk_ping_resp_ts;

/**
 * @brief 获取网络拓扑请求
 */
typedef struct tmpnwk_get_nwk_topology_req
{
    unsigned short nwkaddr;
    unsigned char mode;     /* 0: 通过网络地址获取，1：通过广播获取 */
}__attribute__((__packed__)) tmpnwk_get_nwk_topology_req_ts;


struct neighborinfo
{
    unsigned short neighboraddr;    /*邻居网络地址*/
    unsigned char lqi;              /*邻居链路质量*/
}__attribute__((__packed__));

/**
 * @brief 获取网络拓扑回复
 */
typedef struct tmpnwk_get_nwk_topology_resp
{
    unsigned short nwkaddr;
    unsigned char devicetype;
    unsigned short reserve;
    unsigned char neighbornum;
    struct neighborinfo *pneighborinfo;
}__attribute__((__packed__)) tmpnwk_get_nwk_topology_resp_ts;

//===========================================================================================
//=====================================永久参数配置==========================================
//===========================================================================================


//=====================================本地参数配置==========================================
typedef struct pstloc_conf_read_req
{

}__attribute__((__packed__)) pstloc_conf_read_req_ts;

struct conf_info
{
    char devname[16];
    char passwd[16];
    /*
     * role
     *      0x00 终端设备；
     *      0x01 路由设备；
     *      0x02 协调器；
     */
    unsigned char role;
    char channel;
    unsigned short panid;
    unsigned short nwkaddr;
    unsigned long long macaddr;
    unsigned short dstnwkaddr;
    unsigned long long dstmacaddr;
    /*
     * rxmode
     *      b000 数据;
     *      b001 源网络地址+数据;
     *      b010 源 MAC 地址+数据;
     *      b011 源网络地址+源 MAC 地址+数据;
     *      b100 接收帧格式，
     */
    char rxmode;
    char powerlevel;
    unsigned short dstgroupid;
    /*
     * baudrate
     *      0x01: 2400;
     *      0x02: 4800;
     *      0x03: 9600;
     *      0x04: 19200;
     *      0x05: 38400;
     *      0x06: 57600;
     *      0x07: 115200;
     *      0x08: 230400；
     */
    unsigned char baudrate;
    unsigned char databit;
    unsigned char stopbit;
    unsigned char parity;
    unsigned char txmode;
    unsigned char interval;
    unsigned char reserve0;
    unsigned char reserve1;
}__attribute__((__packed__));

typedef enum running_state
{
    EN_R_STATE_OTA_MODE = 0x55,
    EN_R_STATE_SETTING = 0xF1,
    EN_R_STATE_SETED = 0xAA
} running_state_te;

typedef struct pstloc_conf_read_resp
{
    struct conf_info config;
    /*
     * 运行状态：
     *      0x55：处于升级模式下，仅支持读取本地配置以及升级命令
     *      0xF1：所读配置参数不可靠，需要复位
     *      0xAA：正常配置参数
     */
    unsigned char state;
    unsigned short prototype;
    unsigned short firmwarever;
}__attribute__((__packed__)) pstloc_conf_read_resp_ts;

/**
 * @brief 打开或关闭白名单请求
 */
typedef struct pstloc_enable_whitelist_req
{
    unsigned char rw;
    unsigned char enable;
}__attribute__((__packed__)) pstloc_enable_whitelist_req_ts;

/**
 * @brief 打开或关闭白名单回复
 */
typedef struct pstloc_enable_whitelist_resp
{
    unsigned char enable;
    unsigned char state;
}__attribute__((__packed__)) pstloc_enable_whitelist_resp_ts;

/**
 * @brief 白名单数据操作请求
 */
typedef struct pstloc_opt_whitelist_req
{
    unsigned char opt;
    unsigned long long mac;
} pstloc_opt_whitelist_req_ts;

/**
 * @brief 白名单数据操作回复
 */
typedef struct pstloc_opt_whitelist_resp
{
    unsigned char opt;
    unsigned char num;
    unsigned long long *pmac;
    unsigned char state;
} pstloc_opt_whitelist_resp_ts;

/**
 * @brief 白名单数据操作回复(新接口)
 */
typedef struct pstloc_newopt_whitelist_resp
{
    unsigned char opt;
    unsigned short num;
    unsigned short reserve;
    unsigned long long *pmac;
    unsigned char state;
} pstloc_newopt_whitelist_resp_ts;

/**
 * @brief 配置发送选项请求
 */
typedef struct pstloc_conf_tx_opt_req
{
    /*rw字节为 0，表示该命令为读参数命令，为 1 表示写参数命令，当为读参数命令时，该命令其他字段忽略。*/
    unsigned char rw;
    unsigned short profileid;
    unsigned short clusterid;
    unsigned char srcendpoint;
    unsigned char dstendpoint;
    /*保留字段*/
    unsigned char reserve[6];
}__attribute__((__packed__)) pstloc_conf_tx_opt_req_ts;

/**
 * @brief 配置发送选项回复
 */
typedef struct pstloc_conf_tx_opt_resp
{
    unsigned short profileid;
    unsigned short clusterid;
    unsigned char srcendpoint;
    unsigned char dstendpoint;
    unsigned char reserve[6];
    unsigned char state;
}__attribute__((__packed__)) pstloc_conf_tx_opt_resp_ts;

/**
 * @brief 读取或修改link status周期请求，单位10s
 */
typedef struct pstloc_linkstatus_period_req
{
    unsigned char rw;
    /*
     * period:
     *      0x00：表示当前立即发起一次路径更新请求；
     *      0xFF：表示关闭定时周期请求更新远程路由到本地路由的路径;
     */
    unsigned char period;
}__attribute__((__packed__)) pstloc_linkstatus_period_req_ts;

/**
 * @brief 读取或修改link status周期回复，单位10s
 */
typedef struct pstloc_linkstatus_period_resp
{
    unsigned char period;
    unsigned char state;
}__attribute__((__packed__)) pstloc_linkstatus_period_resp_ts;

/**
 * @brief 组网模式请求
 */
typedef struct pstloc_join_mode_req
{
    unsigned char rw;
    unsigned char mode;
    unsigned char role;
}__attribute__((__packed__)) pstloc_join_mode_req_ts;

/**
 * @brief 组网模式回复
 */
typedef struct pstloc_join_mode_resp
{
    unsigned char mode;
    unsigned char role;
    unsigned char state;
}__attribute__((__packed__)) pstloc_join_mode_resp_ts;

/**
 * @brief 开启zigbee入网许可请求，单位s。仅协调器有效
 */
typedef struct pstloc_permit_join_req
{
    unsigned short duration;    /*0: 关闭入网许可, 0xFFFF: 一直允许入网*/
}__attribute__((__packed__)) pstloc_permit_join_req_ts;

/**
 * @brief 开启zigbee入网许可回复，单位s。仅协调器有效
 */
typedef struct pstloc_permit_join_resp
{
    unsigned short duration;
    unsigned char state;
}__attribute__((__packed__)) pstloc_permit_join_resp_ts;

/**
 * @brief 查询模块入网状态请求
 */
typedef struct pstloc_get_module_status_req
{

}__attribute__((__packed__)) pstloc_get_module_status_req_ts;

enum nwking_state
{
    EN_NWKING_ST_CLOSE = 0x00,      /*协调器空闲，不允许节点加入网络*/
    EN_NWKING_ST_OPEN = 0x01,       /*协调器允许节点加入网络*/
    EN_NWKING_ST_BUSY = 0x02        /*协调器已退出网络*/
};
/**
 * @brief 查询模块入网状态回复
 */
typedef struct pstloc_get_module_status_resp
{
    /*
     * status，角色为协调器时
     *      00: 协调器空闲，不允许节点加入网络
     *      01：协调器允许节点加入网络
     *      02：协调器已退出网络
     *
     * status，角色为节点时
     *      00: 节点正在加入网络
     *      01：节点已加入网络
     *      02：节点已退出网络
     */
    unsigned char status;
    unsigned char state;
}__attribute__((__packed__)) pstloc_get_module_status_reap_ts;

/**
 * @brief 数据备份请求
 */
typedef struct pstloc_backup_req
{
    unsigned short protocol;
}__attribute__((__packed__)) pstloc_backup_req_ts;

/**
 * @brief 数据备份回复
 */
typedef struct pstloc_backup_resp
{
    unsigned short protocol;
    unsigned int size;
    unsigned char state;
}__attribute__((__packed__)) pstloc_backup_resp_ts;

/**
 * @brief 数据恢复请求
 */
typedef struct pstloc_restore_req
{
    unsigned short protocol;
}__attribute__((__packed__)) pstloc_restore_req_ts;

/**
 * @brief 数据恢复回复
 */
typedef struct pstloc_restore_resp
{
    unsigned short protocol;
    unsigned char state;
}__attribute__((__packed__)) pstloc_restore_resp_ts;

//=====================================基于 MAC 地址==========================================
/**
 * @brief 设置信道请求
 */
typedef struct pstmac_set_channel_req
{
    unsigned long long macaddr;
    unsigned char rw;
    unsigned char channel;
    unsigned short reserve;
}__attribute__((__packed__)) pstmac_set_channel_req_ts;

/**
 * @brief 设置信道回复
 */
typedef struct pstmac_set_channel_resp
{
    unsigned long long macaddr;
    unsigned char channel;
    unsigned short reserve;
    unsigned char state;
}__attribute__((__packed__)) pstmac_set_channel_resp_ts;

/**
 * @brief 读写panid请求
 */
typedef struct pstmac_set_panid_req
{
    unsigned long long macaddr;
    unsigned char rw;
    unsigned short panid;
    unsigned short reserve;
}__attribute__((__packed__)) pstmac_set_panid_req_ts;

/**
 * @brief 读写panid回复
 */
typedef struct pstmac_set_panid_resp
{
    unsigned long long macaddr;
    unsigned short panid;
    unsigned short reserve;
    unsigned char state;
}__attribute__((__packed__)) pstmac_set_panid_resp_ts;

/**
 * @brief 读写分组信息请求
 */
typedef struct pstmac_opt_group_req
{
    unsigned long long macaddr;
    unsigned char opt;
    unsigned short groupid;
}__attribute__((__packed__)) pstmac_opt_group_req_ts;

/**
 * @brief 读写分组信息回复
 */
typedef struct pstmac_opt_group_resp
{
    unsigned long long macaddr;
    unsigned char opt;
    unsigned char num;
    unsigned short *pgroupid;
    unsigned char state;
}__attribute__((__packed__)) pstmac_opt_group_resp_ts;

/**
 * @brief 读写目标分组信息请求
 */
typedef struct pstmac_set_dstgroup_req
{
    unsigned long long macaddr;
    unsigned char rw;
    unsigned short dstgroupid;
}__attribute__((__packed__)) pstmac_set_dstgroup_req_ts;

/**
 * @brief 读写目标分组信息回复
 */
typedef struct pstmac_set_dstgroup_resp
{
    unsigned long long macaddr;
    unsigned char rw;
    unsigned short dstgroupid;
    unsigned char state;
}__attribute__((__packed__)) pstmac_set_dstgroup_resp_ts;


/**
 * @brief 搜索网络内的设备请求
 */
typedef struct pstmac_dev_search_req
{

}__attribute__((__packed__)) pstmac_dev_search_req_ts;

/**
 * @brief 搜索网络内的设备回复
 */
typedef struct pstmac_dev_search_resp
{
    unsigned short protocol;
    unsigned char channel;
    unsigned char rate;
    unsigned short panid;
    unsigned short nwkaddr;
    unsigned long long macaddr;
    /*
     *state：运行状态
     *      0xF1：所读配置参数不可靠，需要复位
     *      0xAA：正常配置参数
     */
    unsigned char state;
}__attribute__((__packed__)) pstmac_dev_search_resp_ts;

/**
 * @brief 获取远端设备配置请求
 */
typedef struct pstmac_get_remote_conf_req
{
    unsigned long long macaddr;
}__attribute__((__packed__)) pstmac_get_remote_conf_req_ts;

/**
 * @brief 获取远端设备配置回复
 */
typedef struct pstmac_get_remote_conf_resp
{
    struct conf_info config;
    /*
     *state：运行状态
     *      0xF1：所读配置参数不可靠，需要复位
     *      0xAA：正常配置参数
     */
    unsigned char state;
    unsigned short protocol;
    unsigned short version;
}__attribute__((__packed__)) pstmac_get_remote_conf_resp_ts;

/**
 * @brief 设置远端设备配置请求
 */
typedef struct pstmac_set_remote_conf_req
{
    unsigned long long macaddr;
    struct conf_info config;
}__attribute__((__packed__)) pstmac_set_remote_conf_req_ts;

/**
 * @brief 设置远端设备配置回复
 */
typedef struct pstmac_set_remote_conf_resp
{
    unsigned long long macaddr;
    unsigned char state;
}__attribute__((__packed__)) pstmac_set_remote_conf_resp_ts;

/**
 * @brief 复位远端设备请求，无回复
 */
typedef struct pstmac_reset_remote_req
{
    unsigned long long macaddr;
    unsigned short protocol;
}__attribute__((__packed__)) pstmac_reset_remote_req_ts;

/**
 * @brief 恢复出厂远端设备请求
 */
typedef struct pstmac_restore_remote_req
{
    unsigned long long macaddr;
    unsigned short protocol;
}__attribute__((__packed__)) pstmac_restore_remote_req_ts;

/**
 * @brief 恢复出厂远端设备回复
 */
typedef struct pstmac_restore_remote_resp
{
    unsigned long long macaddr;
    unsigned short protocol;
    unsigned char state;
}__attribute__((__packed__)) pstmac_restore_remote_resp_ts;

/**
 * @brief 模块密码使能读写请求
 */
typedef struct pstmac_enable_passwd_req
{
    unsigned long long macaddr;
    unsigned char rw;
    unsigned char enable;
}__attribute__((__packed__)) pstmac_enable_passwd_req_ts;

/**
 * @brief 模块密码使能读写回复
 */
typedef struct pstmac_enable_passwd_resp
{
    unsigned long long macaddr;
    unsigned char enable;
    unsigned char state;
}__attribute__((__packed__)) pstmac_enable_passwd_resp_ts;

/**
 * @brief 模块登陆或登陆状态查询请求
 */
typedef struct pstmac_rw_passwd_req
{
    unsigned long long macaddr;
    /* rw
     *      0: 获取登陆状态，
     *      1：使用密码进行登陆。
     *  密码的修改是通过配置修改进行的（struct pstmac_set_remote_conf_req or struct pstnwk_set_remote_conf_req）
    */
    unsigned char rw;
    unsigned char passwd[16];
}__attribute__((__packed__)) pstmac_rw_passwd_req_ts;

/**
 * @brief 模块登陆或登陆状态查询回复
 */
typedef struct pstmac_rw_passwd_resp
{
    unsigned long long macaddr;
    unsigned char state;
}__attribute__((__packed__)) pstmac_rw_passwd_resp_ts;


/**
 * @brief IO方向设置或查询请求
 */
typedef struct pstmac_io_dir_req
{
    unsigned long long macaddr;
    unsigned char rw;
    unsigned char io0: 1;
    unsigned char io1: 1;
    unsigned char io2: 1;
    unsigned char io3: 1;
    unsigned char reserve: 4;
}__attribute__((__packed__)) pstmac_io_dir_req_ts;

/**
 * @brief IO方向设置或查询回复
 */
typedef struct pstmac_io_dir_resp
{
    unsigned long long macaddr;
    unsigned char io0: 1;
    unsigned char io1: 1;
    unsigned char io2: 1;
    unsigned char io3: 1;
    unsigned char reserve: 4;
    unsigned char state;
}__attribute__((__packed__)) pstmac_io_dir_resp_ts;

/**
 * @brief io和adc采样配置或查询请求
 */
typedef struct pstmac_sampling_conf_req
{
    unsigned long long macaddr;
    unsigned char rw;
    /*
     * triggerN:通道触发方式
     *      0：下降沿触发
     *      1：上升沿触发
     */
    unsigned char trigger0: 1;
    unsigned char trigger1: 1;
    unsigned char trigger2: 1;
    unsigned char trigger3: 1;
    /*
     * disableN:触发失能
     *      0：使能，自动触发上报
     *      1：失能，不自动触发上报，需要轮询
     */
    unsigned char disable0: 1;
    unsigned char disable1: 1;
    unsigned char disable2: 1;
    unsigned char disable3: 1;
    /*
     * 采样周期，单位100ms
     */
    unsigned short period;
    unsigned char issleep;
}__attribute__((__packed__)) pstmac_sampling_conf_req_ts;

/**
 * @brief io和adc采样配置或查询回复
 */
typedef struct pstmac_sampling_conf_resp
{
    unsigned long long macaddr;
    /*
     * triggerN:通道触发方式
     *      0：下降沿触发
     *      1：上升沿触发
     */
    unsigned char trigger0: 1;
    unsigned char trigger1: 1;
    unsigned char trigger2: 1;
    unsigned char trigger3: 1;
    /*
     * disableN:触发失能
     *      0：使能，自动触发上报
     *      1：失能，不自动触发上报，需要轮询
     */
    unsigned char disable0: 1;
    unsigned char disable1: 1;
    unsigned char disable2: 1;
    unsigned char disable3: 1;
    /*
     * 采样周期，单位100ms
     */
    unsigned short period;
    unsigned char issleep;
    unsigned char state;
}__attribute__((__packed__)) pstmac_sampling_conf_resp_ts;

/**
 * @brief io和adc采样上报
 */
typedef struct pstmac_sampling_report
{
    unsigned long long macaddr;
    /*
     * iolevelN:
     *      0:低电平
     *      1:高电平
     */
    unsigned char iolevel0: 1;
    unsigned char iolevel1: 1;
    unsigned char iolevel2: 1;
    unsigned char iolevel3: 1;
    unsigned char reserve: 4;

    /*
     * 每路adc有10bit采样值，参考电压2.5v
     */
    unsigned short ad0: 10;
    unsigned short reserve0: 6;
    unsigned short ad1: 10;
    unsigned short reserve1: 6;
    unsigned short ad2: 10;
    unsigned short reserve2: 6;
    unsigned short ad3: 10;
    unsigned short reserve3: 6;
}__attribute__((__packed__)) pstmac_sampling_report_ts;

/**
 * @brief io读写请求
 */
typedef struct pstmac_io_rw_req
{
    unsigned long long macaddr;
    unsigned char rw;
    unsigned char iolevel0: 1;
    unsigned char iolevel1: 1;
    unsigned char iolevel2: 1;
    unsigned char iolevel3: 1;
    unsigned char reserve: 4;
}__attribute__((__packed__)) pstmac_io_rw_req_ts;

/**
 * @brief io读写回复
 */
typedef struct pstmac_io_rw_resp
{
    unsigned long long macaddr;
    unsigned char iolevel0: 1;
    unsigned char iolevel1: 1;
    unsigned char iolevel2: 1;
    unsigned char iolevel3: 1;
    unsigned char reserve: 4;
    unsigned char state;
}__attribute__((__packed__)) pstmac_io_rw_resp_ts;

struct pwm_info
{
    unsigned int freq;
    unsigned char duty;
}__attribute__((__packed__));

/**
 * @brief pwm配置或查询请求
 */
typedef struct pstmac_pwm_conf_req
{
    unsigned long long macaddr;
    unsigned char rw;
    struct pwm_info pwm[4];
}__attribute__((__packed__)) pstmac_pwm_conf_req_ts;

/**
 * @brief pwm配置或查询回复
 */
typedef struct pstmac_pwm_conf_resp
{
    unsigned long long macaddr;
    struct pwm_info pwm[4];
    unsigned char state;
}__attribute__((__packed__)) pstmac_pwm_conf_resp_ts;

/**
 * @brief 配置目标网络地址请求
 */
typedef struct pstmac_set_dstnwk_req
{
    unsigned long long macaddr;
    unsigned short dstnwkaddr;
}__attribute__((__packed__)) pstmac_set_dstnwk_req_ts;

/**
 * @brief 配置目标网络地址回复
 */
typedef struct pstmac_set_dstnwk_resp
{
    unsigned long long macaddr;
    unsigned char state;
}__attribute__((__packed__)) pstmac_set_dstnwk_resp_ts;

/**
 * @brief 获取设备角色请求
 */
typedef struct pstmac_get_device_role_req
{
    unsigned long long macaddr;
}__attribute__((__packed__)) pstmac_get_device_role_req_ts;

/**
 * @brief 获取设备角色回复
 */
typedef struct pstmac_get_device_role_resp
{
    unsigned long long macaddr;
    unsigned char role;
}__attribute__((__packed__)) pstmac_get_device_role_resp_ts;

/**
 * @brief 获取节点的子节点mac地址请求
 */
typedef struct pstmac_get_children_mac_req
{
    unsigned long long macaddr;
}__attribute__((__packed__)) pstmac_get_children_mac_req_ts;

/**
 * @brief 获取节点的子节点mac地址回复
 */
typedef struct pstmac_get_children_mac_resp
{
    unsigned long long macaddr;
    unsigned char num;
    unsigned long long *pmacaddr;
}__attribute__((__packed__)) pstmac_get_children_mac_resp_ts;

/**
 * @brief 获取父节点mac地址请求
 */
typedef struct pstmac_get_parent_mac_req
{
    unsigned long long macaddr;
}__attribute__((__packed__)) pstmac_get_parent_mac_req_ts;

/**
 * @brief 获取父节点mac地址回复
 */
typedef struct pstmac_get_parent_mac_resp
{
    unsigned long long macaddr;
    unsigned long long parentmacaddr;
}__attribute__((__packed__)) pstmac_get_parent_mac_resp_ts;

/**
 * @brief 通过mac地址查询设备对应的网络地址请求
 */
typedef struct pstmac_get_nwkaddr_req
{
    unsigned long long macaddr;
}__attribute__((__packed__)) pstmac_get_nwkaddr_req_ts;

/**
 * @brief 通过mac地址查询设备对应的网络地址回复
 */
typedef struct pstmac_get_nwkaddr_resp
{
    unsigned long long macaddr;
    unsigned short nwkaddr;
}__attribute__((__packed__)) pstmac_get_nwkaddr_resp_ts;

/**
 * @brief 设置秘钥请求
 */
typedef struct pstmac_set_key_req
{
    unsigned long long macaddr;
    /*
     * type:秘钥类型
     *      1:预制秘钥
     *      2:网络秘钥
     */
    unsigned char type;
    unsigned char key[16];
}__attribute__((__packed__)) pstmac_set_key_req_ts;

/**
 * @brief 设置秘钥回复
 */
typedef struct pstmac_set_key_resp
{
    unsigned long long macaddr;
    unsigned char state;
}__attribute__((__packed__)) pstmac_set_key_resp_ts;

/**
 * @brief 读取秘钥请求
 */
typedef struct pstmac_get_key_req
{
    unsigned long long macaddr;
    unsigned char type;
}__attribute__((__packed__)) pstmac_get_key_req_ts;

/**
 * @brief 读取秘钥回复
 */
typedef struct pstmac_get_key_resp
{
    unsigned long long macaddr;
    unsigned char type;
    unsigned char key[16];
}__attribute__((__packed__)) pstmac_get_key_resp_ts;

/**
 * @brief 进入升级模式请求
 */
typedef struct pstmac_enter_ota_req
{
    unsigned long long macaddr;
    unsigned char role;
}__attribute__((__packed__)) pstmac_enter_ota_req_ts;

/**
 * @brief 进入升级模式回复
 */
typedef struct pstmac_enter_ota_resp
{
    unsigned long long macaddr;
    unsigned char state;
}__attribute__((__packed__)) pstmac_enter_ota_resp_ts;

/**
 * @brief 开始升级模式请求，然后使用xmode进行固件数据传输
 */
typedef struct pstmac_start_ota_req
{
    unsigned long long macaddr;
    unsigned char role;
}__attribute__((__packed__)) pstmac_start_ota_req_ts;

/**
 * @brief 开始升级模式回复
 */
typedef struct pstmac_start_ota_resp
{
    unsigned long long macaddr;
    /*
     * result
     *      00:固件升级成功
     *      03:固件校验错误
     *      05:固件升级失败
     *      0A:固件与芯片型号不符
     */
    unsigned char result;
}__attribute__((__packed__)) pstmac_start_ota_resp_ts;

/**
 * @brief 读写发送模式请求
 */
typedef struct pstmac_rw_rxmode_req
{
    unsigned long long macaddr;
    unsigned char rw;
    unsigned char mode: 3;
    unsigned char reserve: 5;
}__attribute__((__packed__)) pstmac_rw_rxmode_req_ts;

/**
 * @brief 读写发送模式回复
 */
typedef struct pstmac_rw_rxmode_resp
{
    unsigned long long macaddr;
    unsigned char mode: 3;
    unsigned char reserve: 5;
    unsigned char state;
}__attribute__((__packed__)) pstmac_rw_rxmode_resp_ts;

/**
 * @brief 读写目标mac请求
 */
typedef struct pstmac_rw_dstmac_req
{
    unsigned long long macaddr;
    unsigned char rw;
    unsigned long long dstmacaddr;
}__attribute__((__packed__)) pstmac_rw_dstmac_req_ts;

/**
 * @brief 读写目标mac回复
 */
typedef struct pstmac_rw_dstmac_resp
{
    unsigned long long macaddr;
    unsigned long long dstmacaddr;
    unsigned char state;
}__attribute__((__packed__)) pstmac_rw_dstmac_resp_ts;

/**
 * @brief 读写发送模式请求
 */
typedef struct pstmac_rw_txmode_req
{
    unsigned long long macaddr;
    unsigned char rw;
    /*
     * txmode
     *      0：单播模式
     *      1：广播给所有设备
     *      2：广播给所有非睡眠设备
     *      3：广播给协调器和所有路由器
     *      4：组播模式
     */
    unsigned char txmode: 3;
    unsigned char needsrcmac: 1;
    /*
     * addrtype
     *      0：目标网络地址
     *      1：目标 MAC 地址
     */
    unsigned char addrtype: 1;
    /*
     * format
     *      0：数据（根据数据的目标地址进行发送）
     *      1：指定网络地址+数据
     *      2：指定 MAC 地址+数 据3：发送帧格式
     */
    unsigned char format: 2;
    unsigned char reserve: 1;
}__attribute__((__packed__)) pstmac_rw_txmode_req_ts;

/**
 * @brief 读写发送模式回复
 */
typedef struct pstmac_rw_txmode_resp
{
    unsigned long long macaddr;
    /*
     * txmode
     *      0：单播模式
     *      1：广播给所有设备
     *      2：广播给所有非睡眠设备
     *      3：广播给协调器和所有路由器
     *      4：组播模式
     */
    unsigned char txmode: 3;
    unsigned char needsrcmac: 1;
    /*
     * addrtype
     *      0：目标网络地址
     *      1：目标 MAC 地址
     */
    unsigned char addrtype: 1;
    /*
     * format
     *      0：数据（根据数据的目标地址进行发送）
     *      1：指定网络地址+数据
     *      2：指定 MAC 地址+数 据3：发送帧格式
     */
    unsigned char format: 2;
    unsigned char reserve: 1;
    unsigned char state;
}__attribute__((__packed__)) pstmac_rw_txmode_resp_ts;

/**
 * @brief 读写黑名单使能请求
 */
typedef struct pstmac_rw_blacklist_req
{
    unsigned long long macaddr;
    unsigned char rw;
    unsigned char enable;
}__attribute__((__packed__)) pstmac_rw_blacklist_req_ts;

/**
 * @brief 读写黑名单使能回复
 */
typedef struct pstmac_rw_blacklist_resp
{
    unsigned long long macaddr;
    unsigned char enable;
    unsigned char state;
}__attribute__((__packed__)) pstmac_rw_blacklist_resp_ts;

/**
 * @brief 配置黑名单使能请求
 */
typedef struct pstmac_opt_blacklist_req
{
    unsigned long long macaddr;
    unsigned char opt;
    unsigned short panid;
    unsigned short channelmask;
}__attribute__((__packed__)) pstmac_opt_blacklist_req_ts;

struct blacklist
{
    unsigned short panid;
    unsigned short channelmask;
}__attribute__((__packed__));

/**
 * @brief 配置黑名单使能回复
 */
typedef struct pstmac_opt_blacklist_resp
{
    unsigned long long macaddr;
    unsigned char opt;
    unsigned char num;
    unsigned short channelmask;
    struct blacklist *pblacklist;
}__attribute__((__packed__)) pstmac_opt_blacklist_resp_ts;

//=======================================基于网络地址============================================
/**
 * @brief 设置信道请求
 */
typedef struct pstnwk_set_channel_req
{
    unsigned short nwkaddr;
    unsigned char rw;
    unsigned char channel;
    unsigned short reserve;
}__attribute__((__packed__)) pstnwk_set_channel_req_ts;

/**
 * @brief 设置信道回复
 */
typedef struct pstnwk_set_channel_resp
{
    unsigned short nwkaddr;
    unsigned char channel;
    unsigned short reserve;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_set_channel_resp_ts;

/**
 * @brief 读写panid请求
 */
typedef struct pstnwk_set_panid_req
{
    unsigned short nwkaddr;
    unsigned char rw;
    unsigned short panid;
    unsigned short reserve;
}__attribute__((__packed__)) pstnwk_set_panid_req_ts;

/**
 * @brief 读写panid回复
 */
typedef struct pstnwk_set_panid_resp
{
    unsigned short nwkaddr;
    unsigned short panid;
    unsigned short reserve;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_set_panid_resp_ts;

/**
 * @brief 读写分组信息请求
 */
typedef struct pstnwk_opt_group_req
{
    unsigned short nwkaddr;
    unsigned char opt;
    unsigned short groupid;
}__attribute__((__packed__)) pstnwk_opt_group_req_ts;

/**
 * @brief 读写分组信息回复
 */
typedef struct pstnwk_opt_group_resp
{
    unsigned short nwkaddr;
    unsigned char opt;
    unsigned char num;
    unsigned short *pgroupid;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_opt_group_resp_ts;

/**
 * @brief 读写目标分组信息请求
 */
typedef struct pstnwk_set_dstgroup_req
{
    unsigned short nwkaddr;
    unsigned char rw;
    unsigned short dstgroupid;
}__attribute__((__packed__)) pstnwk_set_dstgroup_req_ts;

/**
 * @brief 读写目标分组信息回复
 */
typedef struct pstnwk_set_dstgroup_resp
{
    unsigned short nwkaddr;
    unsigned char rw;
    unsigned short dstgroupid;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_set_dstgroup_resp_ts;


/**
 * @brief 搜索网络内的设备请求
 */
typedef struct pstnwk_dev_search_req
{

}__attribute__((__packed__)) pstnwk_dev_search_req_ts;

/**
 * @brief 搜索网络内的设备回复
 */
typedef struct pstnwk_dev_search_resp
{
    unsigned short protocol;
    unsigned char channel;
    unsigned char rate;
    unsigned short panid;
    unsigned short nwkaddr;
    /*
     *state：运行状态
     *      0xF1：所读配置参数不可靠，需要复位
     *      0xAA：正常配置参数
     */
    unsigned char state;
}__attribute__((__packed__)) pstnwk_dev_search_resp_ts;

/**
 * @brief 获取远端设备配置请求
 */
typedef struct pstnwk_get_remote_conf_req
{
    unsigned short nwkaddr;
}__attribute__((__packed__)) pstnwk_get_remote_conf_req_ts;

/**
 * @brief 获取远端设备配置回复
 */
typedef struct pstnwk_get_remote_conf_resp
{
    struct conf_info config;
    /*
     *state：运行状态
     *      0xF1：所读配置参数不可靠，需要复位
     *      0xAA：正常配置参数
     */
    unsigned char state;
    unsigned short protocol;
    unsigned short version;
}__attribute__((__packed__)) pstnwk_get_remote_conf_resp_ts;

/**
 * @brief 设置远端设备配置请求
 */
typedef struct pstnwk_set_remote_conf_req
{
    unsigned short nwkaddr;
    struct conf_info config;
}__attribute__((__packed__)) pstnwk_set_remote_conf_req_ts;

/**
 * @brief 设置远端设备配置回复
 */
typedef struct pstnwk_set_remote_conf_resp
{
    unsigned short nwkaddr;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_set_remote_conf_resp_ts;

/**
 * @brief 复位远端设备请求，无回复
 */
typedef struct pstnwk_reset_remote_req
{
    unsigned short nwkaddr;
    unsigned short protocol;
}__attribute__((__packed__)) pstnwk_reset_remote_req_ts;

/**
 * @brief 恢复出厂远端设备请求
 */
typedef struct pstnwk_restore_remote_req
{
    unsigned short nwkaddr;
    unsigned short protocol;
}__attribute__((__packed__)) pstnwk_restore_remote_req_ts;

/**
 * @brief 恢复出厂远端设备回复
 */
typedef struct pstnwk_restore_remote_resp
{
    unsigned short nwkaddr;
    unsigned short protocol;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_restore_remote_resp_ts;

/**
 * @brief 模块密码使能读写请求
 */
typedef struct pstnwk_enable_passwd_req
{
    unsigned short nwkaddr;
    unsigned char rw;
    unsigned char enable;
}__attribute__((__packed__)) pstnwk_enable_passwd_req_ts;

/**
 * @brief 模块密码使能读写回复
 */
typedef struct pstnwk_enable_passwd_resp
{
    unsigned short nwkaddr;
    unsigned char enable;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_enable_passwd_resp_ts;

/**
 * @brief 模块登陆或登陆状态查询请求
 */
typedef struct pstnwk_rw_passwd_req
{
    unsigned short nwkaddr;
    /* rw
     *      0: 获取登陆状态，
     *      1：使用密码进行登陆。
     *  密码的修改是通过配置修改进行的（struct pstnwk_set_remote_conf_req or struct pstnwk_set_remote_conf_req）
    */
    unsigned char rw;
    unsigned char passwd[16];
}__attribute__((__packed__)) pstnwk_rw_passwd_req_ts;

/**
 * @brief 模块登陆或登陆状态查询回复
 */
typedef struct pstnwk_rw_passwd_resp
{
    unsigned short nwkaddr;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_rw_passwd_resp_ts;


/**
 * @brief IO方向设置或查询请求
 */
typedef struct pstnwk_io_dir_req
{
    unsigned short nwkaddr;
    unsigned char rw;
    unsigned char io0: 1;
    unsigned char io1: 1;
    unsigned char io2: 1;
    unsigned char io3: 1;
    unsigned char reserve: 4;
}__attribute__((__packed__)) pstnwk_io_dir_req_ts;

/**
 * @brief IO方向设置或查询回复
 */
typedef struct pstnwk_io_dir_resp
{
    unsigned short nwkaddr;
    unsigned char io0: 1;
    unsigned char io1: 1;
    unsigned char io2: 1;
    unsigned char io3: 1;
    unsigned char reserve: 4;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_io_dir_resp_ts;

/**
 * @brief io和adc采样配置或查询请求
 */
typedef struct pstnwk_sampling_conf_req
{
    unsigned short nwkaddr;
    unsigned char rw;
    /*
     * triggerN:通道触发方式
     *      0：下降沿触发
     *      1：上升沿触发
     */
    unsigned char trigger0: 1;
    unsigned char trigger1: 1;
    unsigned char trigger2: 1;
    unsigned char trigger3: 1;
    /*
     * disableN:触发失能
     *      0：使能，自动触发上报
     *      1：失能，不自动触发上报，需要轮询
     */
    unsigned char disable0: 1;
    unsigned char disable1: 1;
    unsigned char disable2: 1;
    unsigned char disable3: 1;
    /*
     * 采样周期，单位100ms
     */
    unsigned short period;
    unsigned char issleep;
}__attribute__((__packed__)) pstnwk_sampling_conf_req_ts;

/**
 * @brief io和adc采样配置或查询回复
 */
typedef struct pstnwk_sampling_conf_resp
{
    unsigned short nwkaddr;
    /*
     * triggerN:通道触发方式
     *      0：下降沿触发
     *      1：上升沿触发
     */
    unsigned char trigger0: 1;
    unsigned char trigger1: 1;
    unsigned char trigger2: 1;
    unsigned char trigger3: 1;
    /*
     * disableN:触发失能
     *      0：使能，自动触发上报
     *      1：失能，不自动触发上报，需要轮询
     */
    unsigned char disable0: 1;
    unsigned char disable1: 1;
    unsigned char disable2: 1;
    unsigned char disable3: 1;
    /*
     * 采样周期，单位100ms
     */
    unsigned short period;
    unsigned char issleep;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_sampling_conf_resp_ts;

/**
 * @brief io和adc采样上报
 */
typedef struct pstnwk_sampling_report
{
    unsigned short nwkaddr;
    /*
     * iolevelN:
     *      0:低电平
     *      1:高电平
     */
    unsigned char iolevel0: 1;
    unsigned char iolevel1: 1;
    unsigned char iolevel2: 1;
    unsigned char iolevel3: 1;
    unsigned char reserve: 4;

    /*
     * 每路adc有10bit采样值，参考电压2.5v
     */
    unsigned short ad0: 10;
    unsigned short reserve0: 6;
    unsigned short ad1: 10;
    unsigned short reserve1: 6;
    unsigned short ad2: 10;
    unsigned short reserve2: 6;
    unsigned short ad3: 10;
    unsigned short reserve3: 6;
}__attribute__((__packed__)) pstnwk_sampling_report_ts;

/**
 * @brief io读写请求
 */
typedef struct pstnwk_io_rw_req
{
    unsigned short nwkaddr;
    unsigned char rw;
    unsigned char iolevel0: 1;
    unsigned char iolevel1: 1;
    unsigned char iolevel2: 1;
    unsigned char iolevel3: 1;
    unsigned char reserve: 4;
}__attribute__((__packed__)) pstnwk_io_rw_req_ts;

/**
 * @brief io读写回复
 */
typedef struct pstnwk_io_rw_resp
{
    unsigned short nwkaddr;
    unsigned char iolevel0: 1;
    unsigned char iolevel1: 1;
    unsigned char iolevel2: 1;
    unsigned char iolevel3: 1;
    unsigned char reserve: 4;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_io_rw_resp_ts;

/**
 * @brief pwm配置或查询请求
 */
typedef struct pstnwk_pwm_conf_req
{
    unsigned short nwkaddr;
    unsigned char rw;
    struct pwm_info pwm[4];
}__attribute__((__packed__)) pstnwk_pwm_conf_req_ts;

/**
 * @brief pwm配置或查询回复
 */
typedef struct pstnwk_pwm_conf_resp
{
    unsigned short nwkaddr;
    struct pwm_info pwm[4];
    unsigned char state;
}__attribute__((__packed__)) pstnwk_pwm_conf_resp_ts;

/**
 * @brief 配置目标网络地址请求
 */
typedef struct pstnwk_set_dstnwk_req
{
    unsigned short nwkaddr;
    unsigned short dstnwkaddr;
}__attribute__((__packed__)) pstnwk_set_dstnwk_req_ts;

/**
 * @brief 配置目标网络地址回复
 */
typedef struct pstnwk_set_dstnwk_resp
{
    unsigned short nwkaddr;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_set_dstnwk_resp_ts;

/**
 * @brief 获取设备角色请求
 */
typedef struct pstnwk_get_device_role_req
{
    unsigned short nwkaddr;
}__attribute__((__packed__)) pstnwk_get_device_role_req_ts;

/**
 * @brief 获取设备角色回复
 */
typedef struct pstnwk_get_device_role_resp
{
    unsigned short nwkaddr;
    unsigned char role;
}__attribute__((__packed__)) pstnwk_get_device_role_resp_ts;

/**
 * @brief 获取节点的子节点网络地址请求
 */
typedef struct pstnwk_get_children_nwk_req
{
    unsigned short nwkaddr;
}__attribute__((__packed__)) pstnwk_get_children_nwk_req_ts;

/**
 * @brief 获取节点的子节点网络地址回复
 */
typedef struct pstnwk_get_children_nwk_resp
{
    unsigned short nwkaddr;
    unsigned char num;
    unsigned short *pnwkaddr;
}__attribute__((__packed__)) pstnwk_get_children_nwk_resp_ts;

/**
 * @brief 获取父节点网络地址请求
 */
typedef struct pstnwk_get_parent_mac_req
{
    unsigned short nwkaddr;
}__attribute__((__packed__)) pstnwk_get_parent_mac_req_ts;

/**
 * @brief 获取父节点网络地址回复
 */
typedef struct pstnwk_get_parent_nwk_resp
{
    unsigned short nwkaddr;
    unsigned long long parentnwkaddr;
}__attribute__((__packed__)) pstnwk_get_parent_nwk_resp_ts;

/**
 * @brief 通过网络地址查询设备对应的mac地址请求
 */
typedef struct pstnwk_get_macaddr_req
{
    unsigned short nwkaddr;
}__attribute__((__packed__)) pstnwk_get_macaddr_req_ts;

/**
 * @brief 通过网络地址查询设备对应的mac地址回复
 */
typedef struct pstnwk_get_macaddr_resp
{
    unsigned short nwkaddr;
    unsigned long long macaddr;
}__attribute__((__packed__)) pstnwk_get_macaddr_resp_ts;

/**
 * @brief 设置秘钥请求
 */
typedef struct pstnwk_set_key_req
{
    unsigned short nwkaddr;
    /*
     * type:秘钥类型
     *      1:预制秘钥
     *      2:网络秘钥
     */
    unsigned char type;
    unsigned char key[16];
}__attribute__((__packed__)) pstnwk_set_key_req_ts;

/**
 * @brief 设置秘钥回复
 */
typedef struct pstnwk_set_key_resp
{
    unsigned short nwkaddr;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_set_key_resp_ts;

/**
 * @brief 读取秘钥请求
 */
typedef struct pstnwk_get_key_req
{
    unsigned short nwkaddr;
    unsigned char type;
}__attribute__((__packed__)) pstnwk_get_key_req_ts;

/**
 * @brief 读取秘钥回复
 */
typedef struct pstnwk_get_key_resp
{
    unsigned short nwkaddr;
    unsigned char type;
    unsigned char key[16];
}__attribute__((__packed__)) pstnwk_get_key_resp_ts;

/**
 * @brief 进入升级模式请求
 */
typedef struct pstnwk_enter_ota_req
{
    unsigned short nwkaddr;
    unsigned char role;
}__attribute__((__packed__)) pstnwk_enter_ota_req_ts;

/**
 * @brief 进入升级模式回复
 */
typedef struct pstnwk_enter_ota_resp
{
    unsigned short nwkaddr;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_enter_ota_resp_ts;

/**
 * @brief 开始升级模式请求，然后使用xmode进行固件数据传输
 */
typedef struct pstnwk_start_ota_req
{
    unsigned short nwkaddr;
    unsigned char role;
}__attribute__((__packed__)) pstnwk_start_ota_req_ts;

/**
 * @brief 开始升级模式回复
 */
typedef struct pstnwk_start_ota_resp
{
    unsigned short nwkaddr;
    /*
     * result
     *      00:固件升级成功
     *      03:固件校验错误
     *      05:固件升级失败
     *      0A:固件与芯片型号不符
     */
    unsigned char result;
}__attribute__((__packed__)) pstnwk_start_ota_resp_ts;

/**
 * @brief 读写发送模式请求
 */
typedef struct pstnwk_rw_rxmode_req
{
    unsigned short nwkaddr;
    unsigned char rw;
    unsigned char mode: 3;
    unsigned char reserve: 5;
}__attribute__((__packed__)) pstnwk_rw_rxmode_req_ts;

/**
 * @brief 读写发送模式回复
 */
typedef struct pstnwk_rw_rxmode_resp
{
    unsigned short nwkaddr;
    unsigned char mode: 3;
    unsigned char reserve: 5;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_rw_rxmode_resp_ts;

/**
 * @brief 读写目标mac请求
 */
typedef struct pstnwk_rw_dstmac_req
{
    unsigned short nwkaddr;
    unsigned char rw;
    unsigned long long dstmacaddr;
}__attribute__((__packed__)) pstnwk_rw_dstmac_req_ts;

/**
 * @brief 读写目标mac回复
 */
typedef struct pstnwk_rw_dstmac_resp
{
    unsigned short nwkaddr;
    unsigned long long dstmacaddr;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_rw_dstmac_resp_ts;

/**
 * @brief 读写发送模式请求
 */
typedef struct pstnwk_rw_txmode_req
{
    unsigned short nwkaddr;
    unsigned char rw;
    /*
     * txmode
     *      0：单播模式
     *      1：广播给所有设备
     *      2：广播给所有非睡眠设备
     *      3：广播给协调器和所有路由器
     *      4：组播模式
     */
    unsigned char txmode: 3;
    unsigned char needsrcmac: 1;
    /*
     * addrtype
     *      0：目标网络地址
     *      1：目标 MAC 地址
     */
    unsigned char addrtype: 1;
    /*
     * format
     *      0：数据（根据数据的目标地址进行发送）
     *      1：指定网络地址+数据
     *      2：指定 MAC 地址+数 据3：发送帧格式
     */
    unsigned char format: 2;
    unsigned char reserve: 1;
}__attribute__((__packed__)) pstnwk_rw_txmode_req_ts;

/**
 * @brief 读写发送模式回复
 */
typedef struct pstnwk_rw_txmode_resp
{
    unsigned short nwkaddr;
    /*
     * txmode
     *      0：单播模式
     *      1：广播给所有设备
     *      2：广播给所有非睡眠设备
     *      3：广播给协调器和所有路由器
     *      4：组播模式
     */
    unsigned char txmode: 3;
    unsigned char needsrcmac: 1;
    /*
     * addrtype
     *      0：目标网络地址
     *      1：目标 MAC 地址
     */
    unsigned char addrtype: 1;
    /*
     * format
     *      0：数据（根据数据的目标地址进行发送）
     *      1：指定网络地址+数据
     *      2：指定 MAC 地址+数 据3：发送帧格式
     */
    unsigned char format: 2;
    unsigned char reserve: 1;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_rw_txmode_resp_ts;


/**
 * @brief 设置广播命令应答延时请求。
 */
typedef struct pstnwk_rw_bc_ack_delay_req
{
    unsigned short reserve0;
    unsigned char rw;
    /*
     * opt
     *      0：本地控制
     *      1：广播控制-远程设备不用应答
     *      2：广播控制-远程设备应答
     */
    unsigned char opt;
    /*移动位数*/
    unsigned char shiftbit: 3;
    unsigned char reserve1: 4;
    /*移动方向， 0:右移 1:左移*/
    unsigned char shiftdir: 1;
}__attribute__((__packed__)) pstnwk_rw_bc_ack_delay_req_ts;

/**
 * @brief 设置广播命令应答延时回复。
 */
typedef struct pstnwk_rw_bc_ack_delay_resp
{
    unsigned short nwkaddr;
    /*
     * opt
     *      0：本地控制
     *      1：广播控制-远程设备不用应答
     *      2：广播控制-远程设备应答
     */
    unsigned char opt;
    /*移动位数*/
    unsigned char shiftbit: 3;
    unsigned char reserve1: 4;
    /*移动方向， 0:右移 1:左移*/
    unsigned char shiftdir: 1;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_rw_bc_ack_delay_resp_ts;


/**
 * @brief 读写黑名单使能请求
 */
typedef struct pstnwk_rw_blacklist_req
{
    unsigned short nwkaddr;
    unsigned char rw;
    unsigned char enable;
}__attribute__((__packed__)) pstnwk_rw_blacklist_req_ts;

/**
 * @brief 读写黑名单使能回复
 */
typedef struct pstnwk_rw_blacklist_resp
{
    unsigned short nwkaddr;
    unsigned char enable;
    unsigned char state;
}__attribute__((__packed__)) pstnwk_rw_blacklist_resp_ts;

/**
 * @brief 配置黑名单使能请求
 */
typedef struct pstnwk_opt_blacklist_req
{
    unsigned short nwkaddr;
    unsigned char opt;
    unsigned short panid;
    unsigned short channelmask;
}__attribute__((__packed__)) pstnwk_opt_blacklist_req_ts;

/**
 * @brief 配置黑名单使能回复
 */
typedef struct pstnwk_opt_blacklist_resp
{
    unsigned short nwkaddr;
    unsigned char opt;
    unsigned char num;
    unsigned short channelmask;
    struct blacklist *pblacklist;
}__attribute__((__packed__)) pstnwk_opt_blacklist_resp_ts;

//========================================特殊帧===============================================

typedef struct frame_rtx
{
    unsigned long long macaddr;
    unsigned short nwkaddr;
    unsigned short length;
    unsigned char payload[1];
    unsigned char checksum;
} frame_rtx_ts;


typedef struct group_frame_tx
{
    unsigned short groupid;
    unsigned short length;
    unsigned char *payload;
    unsigned char checksum;
} group_frame_tx_ts;


typedef struct group_frame_rx
{
    unsigned short groupid;
    unsigned long long srcmacaddr;
    unsigned short srcnwkaddr;
    unsigned short length;
    unsigned char payload[1];
    unsigned char checksum;
} group_frame_rx_ts;


#endif //__ZM32_MESSAGE_H__
